package com.course.mapper;

import com.course.dto.StuUpdateDTO;
import com.course.dto.updatePassword;
import com.course.entity.SC;
import com.course.entity.Student;
import com.course.vo.ChooseCourse;
import com.course.vo.StudentCredit;
import com.course.vo.StudentsCourse;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StuMapper {
    /**
     * 插入新学生的数据
     * @param student
     */
    @Insert("insert into student(sname,ssex,sage,create_time,update_time)"+
            "values "+"(#{sname},#{ssex},#{sage},#{createTime},#{updateTime})")
    void insert(Student student);

    /**
     * 查询学生信息
     * @return
     */
    List<Student> list(@Param("sno")Integer sno,@Param("sname")String sname);

    List<Student> page(Integer sno,String sname);
    /**
     * 删除学生信息
     * @param sno
     */
    @Delete("delete from student where sno=#{sno}")
    void deleteBySNO(Integer sno);

    /**
     * 根据学号查询学生信息
     * @param sno
     * @return
     */
    @Select("select * from student where sno=#{sno}")
    List<Student> list2(Integer sno);

    /**
     * 更新学生
     * @param student
     */
    void update(Student student);

    /**
     * 查询学生获得的学分
     * @return
     */
    @Select("select sno,allcredit,passcredit from studentinfo where sno=#{sno}")
    List<StudentCredit> studentCredit(Integer sno);

    /**
     * 学生选课
     * @param sc
     */
    @Insert("insert into sc(sno,cno,grade) values (#{sno},#{cno},#{grade}) ")
    void ChooseCourse(SC sc);

    /**
     * 查询学生课程成绩
     * @param sno
     * @return
     */
    @Select("SELECT sc.sno, sc.cno, course.cname, sc.grade,course.credit FROM sc INNER JOIN course ON sc.cno = course.cno WHERE sc.sno = #{sno}")
    List<StudentsCourse> GetCourse(@Param("sno") Integer sno);

    /**
     * 退选课程
     * @param sno
     * @param cno
     */
    @Delete("delete from sc where cno=#{cno} and sno=#{sno}")
    void deleteByCNO(Integer sno,String cno);

    /**
     * 登录操作
     * @param student
     * @return
     */
    @Select("select * from student where username=#{username} and password=#{password}")
    Student getByUsernameAndPassword(Student student);

    /**
     * 更新学生成绩
     */
    void Grade(SC sc);

    /**
     * 更新学生密码
     * @param sno
     */
    @Update("update student set password='123456' where sno=#{sno}")
    void updatePassword(Integer sno);

    /**
     * 学生自定义修改密码
     * @param toupdatePassword
     */
    void definePassword(updatePassword toupdatePassword);
}
